package com.otod.sys.amcm.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.otod.base.service.BaseService;
import com.otod.commons.constants.CommonConstant;
import com.otod.commons.entity.Page;
import com.otod.commons.utils.DateUtils;
import com.otod.pm.prj.vo.TaskVo;
import com.otod.sys.amcm.mapper.AmcmMsgAppMapper;
import com.otod.sys.vo.AmcmMsgAppVo;

@Service
@Transactional(readOnly=true)
public class AmcmMsgAppService extends BaseService{
	
	@Autowired
	AmcmMsgAppMapper amcmMsgAppMapper;
	public List<AmcmMsgAppVo> queryForlist(Map<String, Object> param){
		List<AmcmMsgAppVo> amcmMsgAppVos = Lists.newArrayList();
		amcmMsgAppVos = amcmMsgAppMapper.queryForList(param);
		return amcmMsgAppVos;
	}
	/**
	 * 分页查询项目信息列表
	 * @param page	分页信息
	 * @param param	参数
	 * @return	分页信息和结果数据
	 */
	public Page queryPageForList(Page page,Map<String,Object> param){
		List<AmcmMsgAppVo> dataList =  amcmMsgAppMapper.queryForList(page,param);
		page.setAaData(dataList);
		return page;
	}
	/**
	 * 通过uuid查询数据
	 */
	public AmcmMsgAppVo getAmcmMsgApp(String uuid){	
		AmcmMsgAppVo amcmMsgAppVo = null;
		amcmMsgAppVo = amcmMsgAppMapper.getById(uuid);
		return amcmMsgAppVo;
	}
	/**
	 * 通过uuid删除数据
	 */
	@Transactional
	public void deleteById(String uuid){	
		amcmMsgAppMapper.deleteById(uuid);
	}
	/**
	 * 修改为已读
	 * @param uuid
	 */
	@Transactional
	public void updateIsRead(String uuid){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uuid", uuid);
		map.put("isRead", CommonConstant.COMMON_YES);
		map.put("msgReadDt", new Date());
		amcmMsgAppMapper.update(map);
	}
	/**
	 * install messageVo
	 * @param vo
	 * @param message
	 * @return
	 */
	@Transactional
	public AmcmMsgAppVo installMsgVo(TaskVo vo,String message){
		AmcmMsgAppVo msg = new AmcmMsgAppVo();
		msg.setBusiName(vo.getTaskName());
		msg.setBusiUrl("/jsp/pm/prj/step.jsp?prjId="+vo.getPrjId());
		msg.setBusiValue(vo.getUuid());
		msg.setMsgTitle("任务："+vo.getTaskName()+"...有新消息了！");
		msg.setMsgInfo(message+vo.getTaskName());
		msg.setEmpNo(vo.getEmpNo());
		msg.setEmp(vo.getEmpName());
		msg.setIsRead(CommonConstant.COMMON_NO);
		msg.setMsgCrateDt(DateUtils.getCurrentDate());
		msg.setUuid(super.getUUID());
		amcmMsgAppMapper.insert(msg);
		return msg;
	}
}
